package com.czxy.service;

import com.czxy.damain.Student;
import com.czxy.dao.StudentMapper;
import com.czxy.utils.MybatisUtil;

import java.util.List;

public class StudentService {

    //根据id 查询用户

    public String findStudentById(String sid){

        StudentMapper mapper = MybatisUtil.getMapper(StudentMapper.class);

        mapper.findStudentById(sid);


        MybatisUtil.close();

        return null;
    }





    //确定编辑
    public  boolean update(Student student){

        StudentMapper mapper = MybatisUtil.getMapper(StudentMapper.class);

        List<Student> list = mapper.getRNameStudent(student);

        if (list.size()!=0){

            MybatisUtil.close();
            return false;
        }else{

            mapper.update(student);
            MybatisUtil.commitAndclose();
            return true;
        }


    }




    public  Student findStudentId(String sid){

        StudentMapper mapper = MybatisUtil.getMapper(StudentMapper.class);

        Student student = mapper.findStudentId(sid);


        MybatisUtil.close();


        return student;



    }

















    public boolean  add(Student student){

        StudentMapper mapper = MybatisUtil.getMapper(StudentMapper.class);


        List<Student> list = mapper.findLoginName(student);


        if (list.size()!=0) {

            //失败
            MybatisUtil.close();

            return false;
        }else{

            mapper.insert(student);

            MybatisUtil.commitAndclose();

            return true;
        }


    }
    //


    //删除

    public  void delete(java.lang.String sid){


        StudentMapper mapper = MybatisUtil.getMapper(StudentMapper.class);

        mapper.delete(sid);


        MybatisUtil.commitAndclose();


    }
















    //根据用户名查询

    public  List<Student> findName(String studentname){

        StudentMapper mapper = MybatisUtil.getMapper(StudentMapper.class);


        List<Student> list = mapper.findName("%"+studentname+"%");



        MybatisUtil.close();

        return list;
    }







    //查询所有
    public List<Student> findAll(){

        StudentMapper mapper = MybatisUtil.getMapper(StudentMapper.class);

        List<Student> list = mapper.findAll();


        MybatisUtil.close();


        return  list;
    }




}
